package com.blog.cmrpersonalblog.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blog.cmrpersonalblog.dto.article.request.ArticleTagCreateRequest;
import com.blog.cmrpersonalblog.dto.article.request.ArticleTagQueryRequest;
import com.blog.cmrpersonalblog.dto.article.request.ArticleTagUpdateRequest;
import com.blog.cmrpersonalblog.dto.article.response.ArticleTagResponse;
import com.blog.cmrpersonalblog.dto.tag.requset.TagBatchOperationRequest;
import com.blog.cmrpersonalblog.dto.tag.requset.TagCreateRequest;
import com.blog.cmrpersonalblog.dto.tag.requset.TagQueryRequest;
import com.blog.cmrpersonalblog.dto.tag.requset.TagUpdateRequest;
import com.blog.cmrpersonalblog.dto.tag.respnose.TagManagementResponse;
import com.blog.cmrpersonalblog.entity.ArticleTag;
import com.blog.cmrpersonalblog.mapper.ArticleTagMapper;
import com.blog.cmrpersonalblog.mapper.TagMapper;
import com.blog.cmrpersonalblog.service.ArticleTagRelationService;
import com.blog.cmrpersonalblog.service.TagManagementService;
import com.blog.cmrpersonalblog.service.UserActivityService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 标签管理服务实现类
 */
@Slf4j
@Service
public class TagManagementServiceImpl implements TagManagementService {

   @Resource
    private TagMapper tagMapper;

   @Resource
    private ArticleTagMapper articleTagMapper;

   @Resource
    private ArticleTagRelationService articleTagRelationService;

   @Resource
    private UserActivityService userActivityService;

    @Override
    public IPage<TagManagementResponse> getTagList(TagQueryRequest queryRequest) {
        Page<TagManagementResponse> page = new Page<>(queryRequest.getSafeCurrent(), queryRequest.getSafeSize());
        return tagMapper.selectTagManagementPage(page, queryRequest);
    }

    @Override
    public TagManagementResponse getTagDetail(Long tagId) {
        if (tagId == null) {
            return null;
        }
        TagManagementResponse response = tagMapper.selectTagDetailById(tagId);
        if (response != null) {
            // 获取最近使用的文章标题
            List<String> recentTitles = tagMapper.selectRecentArticleTitlesByTagId(tagId, 5);
            response.setRecentArticleTitles(recentTitles);
        }
        return response;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean createTag(TagCreateRequest createRequest, Long operatorId) {
        try {
            if (!createRequest.isValid()) {
                throw new RuntimeException("请求参数无效");
            }

            // 检查标签名称是否已存在
            if (existsTagName(createRequest.getCleanName(), null)) {
                throw new RuntimeException("标签名称已存在");
            }

            // 检查是否包含特殊字符
            if (createRequest.hasSpecialCharacters()) {
                throw new RuntimeException("标签名称不能包含特殊字符");
            }

            // 创建标签
            ArticleTag tag = new ArticleTag();
            tag.setName(createRequest.getCleanName());
            tag.setColor(createRequest.getSafeColor());
            tag.setStatus(createRequest.getStatus());
            tag.setUseCount(0);
            tag.setCreateTime(LocalDateTime.now());
            tag.setUpdateTime(LocalDateTime.now());

            int result = tagMapper.insert(tag);
            if (result > 0) {
                // 记录创建活动
                userActivityService.recordActivity(operatorId, "TAG_CREATED", "创建标签",
                    tag.getId(), "tag", "SUCCESS", 
                    Map.of("tagName", createRequest.getCleanName(), 
                           "tagColor", createRequest.getSafeColor()));

                log.info("标签创建成功: tagId={}, name={}, operatorId={}", 
                    tag.getId(), createRequest.getCleanName(), operatorId);
                return true;
            }

            return false;
        } catch (Exception e) {
            log.error("标签创建失败", e);
            throw new RuntimeException(e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateTag(TagUpdateRequest updateRequest, Long operatorId) {
        try {
            if (!updateRequest.isValid()) {
                throw new RuntimeException("请求参数无效");
            }

            // 检查标签是否存在
            ArticleTag existingTag = tagMapper.selectById(updateRequest.getId());
            if (existingTag == null) {
                throw new RuntimeException("标签不存在");
            }

            // 检查标签名称是否已存在（排除当前标签）
            if (existsTagName(updateRequest.getCleanName(), updateRequest.getId())) {
                throw new RuntimeException("标签名称已存在");
            }

            // 检查是否包含特殊字符
            if (updateRequest.hasSpecialCharacters()) {
                throw new RuntimeException("标签名称不能包含特殊字符");
            }

            // 检查是否有实际的更新内容
            if (!updateRequest.hasChanges(existingTag.getName(), existingTag.getColor(), existingTag.getStatus())) {
                return true; // 没有变化，直接返回成功
            }

            // 更新标签
            ArticleTag tag = new ArticleTag();
            tag.setId(updateRequest.getId());
            tag.setName(updateRequest.getCleanName());
            tag.setColor(updateRequest.getSafeColor());
            tag.setStatus(updateRequest.getStatus());
            tag.setUpdateTime(LocalDateTime.now());

            int result = tagMapper.updateById(tag);
            if (result > 0) {
                // 记录更新活动
                userActivityService.recordActivity(operatorId, "TAG_UPDATED", "更新标签",
                    tag.getId(), "tag", "SUCCESS", 
                    Map.of("tagName", updateRequest.getCleanName(), 
                           "oldName", existingTag.getName(),
                           "tagColor", updateRequest.getSafeColor(),
                           "oldColor", existingTag.getColor()));

                log.info("标签更新成功: tagId={}, name={}, operatorId={}", 
                    tag.getId(), updateRequest.getCleanName(), operatorId);
                return true;
            }

            return false;
        } catch (Exception e) {
            log.error("标签更新失败", e);
            throw new RuntimeException("标签更新失败: " + e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteTag(Long tagId, Long operatorId) {
        try {
            // 检查标签是否存在
            ArticleTag tag = tagMapper.selectById(tagId);
            if (tag == null) {
                throw new RuntimeException("标签不存在");
            }

            // 检查标签是否被文章使用
            if (isTagUsedByArticles(tagId)) {
                throw new RuntimeException("标签正在被文章使用，无法删除");
            }

            // 删除标签
            int result = tagMapper.deleteById(tagId);
            if (result > 0) {
                // 记录删除活动
                userActivityService.recordActivity(operatorId, "TAG_DELETED", "删除标签",
                    tagId, "tag", "SUCCESS", 
                    Map.of("tagName", tag.getName(), 
                           "tagColor", tag.getColor(),
                           "useCount", tag.getUseCount()));

                log.info("标签删除成功: tagId={}, name={}, operatorId={}", 
                    tagId, tag.getName(), operatorId);
                return true;
            }

            return false;
        } catch (Exception e) {
            log.error("标签删除失败", e);
            throw new RuntimeException("标签删除失败: " + e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> batchOperateTags(TagBatchOperationRequest batchRequest, Long operatorId) {
        Map<String, Object> result = new HashMap<>();
        
        try {
            String operation = batchRequest.getOperation();
            List<Long> tagIds = batchRequest.getTagIds();
            int affectedRows = 0;

            switch (operation) {
                case "enable":
                    affectedRows = tagMapper.batchUpdateTagStatus(tagIds, 1);
                    break;
                case "disable":
                    affectedRows = tagMapper.batchUpdateTagStatus(tagIds, 0);
                    break;
                case "delete":
                    // 批量检查是否有标签被文章使用（优化：避免N+1查询）
                    // 使用一次查询检查所有标签的使用情况
                    List<ArticleTag> tagsToDelete = articleTagMapper.selectTagsByIds(tagIds);
                    for (ArticleTag tag : tagsToDelete) {
                        if (tag.getUseCount() != null && tag.getUseCount() > 0) {
                            throw new RuntimeException("标签 \"" + tag.getName() + "\" 正在被文章使用，无法删除");
                        }
                    }
                    affectedRows = tagMapper.batchDeleteTags(tagIds);
                    break;
                case "resetUseCount":
                    affectedRows = tagMapper.batchResetTagUseCount(tagIds);
                    break;
                default:
                    throw new RuntimeException("不支持的操作类型: " + operation);
            }

            result.put("success", affectedRows > 0);
            result.put("affectedRows", affectedRows);
            result.put("operation", operation);

            if (affectedRows > 0) {
                log.info("标签批量操作成功: operation={}, affectedRows={}, operatorId={}", 
                    operation, affectedRows, operatorId);
            }

            return result;
        } catch (Exception e) {
            log.error("标签批量操作失败", e);
            result.put("success", false);
            result.put("error", e.getMessage());
            return result;
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean enableTag(Long tagId, Long operatorId) {
        try {
            ArticleTag tag = tagMapper.selectById(tagId);
            if (tag == null) {
                throw new RuntimeException("标签不存在");
            }

            tag.setStatus(1);
            tag.setUpdateTime(LocalDateTime.now());
            
            int result = tagMapper.updateById(tag);
            if (result > 0) {
                userActivityService.recordActivity(operatorId, "TAG_ENABLED", "启用标签",
                    tagId, "tag", "SUCCESS", 
                    Map.of("tagName", tag.getName()));
                
                log.info("标签启用成功: tagId={}, operatorId={}", tagId, operatorId);
                return true;
            }
            
            return false;
        } catch (Exception e) {
            log.error("标签启用失败", e);
            throw new RuntimeException("标签启用失败: " + e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean disableTag(Long tagId, Long operatorId) {
        try {
            ArticleTag tag = tagMapper.selectById(tagId);
            if (tag == null) {
                throw new RuntimeException("标签不存在");
            }

            tag.setStatus(0);
            tag.setUpdateTime(LocalDateTime.now());
            
            int result = tagMapper.updateById(tag);
            if (result > 0) {
                userActivityService.recordActivity(operatorId, "TAG_DISABLED", "禁用标签",
                    tagId, "tag", "SUCCESS", 
                    Map.of("tagName", tag.getName()));
                
                log.info("标签禁用成功: tagId={}, operatorId={}", tagId, operatorId);
                return true;
            }
            
            return false;
        } catch (Exception e) {
            log.error("标签禁用失败", e);
            throw new RuntimeException("标签禁用失败: " + e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateTagColor(Long tagId, String color, Long operatorId) {
        try {
            ArticleTag tag = tagMapper.selectById(tagId);
            if (tag == null) {
                throw new RuntimeException("标签不存在");
            }

            String oldColor = tag.getColor();
            tag.setColor(color);
            tag.setUpdateTime(LocalDateTime.now());
            
            int result = tagMapper.updateById(tag);
            if (result > 0) {
                userActivityService.recordActivity(operatorId, "TAG_COLOR_UPDATED", "更新标签颜色",
                    tagId, "tag", "SUCCESS", 
                    Map.of("tagName", tag.getName(), 
                           "oldColor", oldColor,
                           "newColor", color));
                
                log.info("标签颜色更新成功: tagId={}, color={}, operatorId={}", 
                    tagId, color, operatorId);
                return true;
            }
            
            return false;
        } catch (Exception e) {
            log.error("标签颜色更新失败", e);
            throw new RuntimeException("标签颜色更新失败: " + e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean resetTagUseCount(Long tagId, Long operatorId) {
        try {
            ArticleTag tag = tagMapper.selectById(tagId);
            if (tag == null) {
                throw new RuntimeException("标签不存在");
            }

            Integer oldUseCount = tag.getUseCount();
            int result = tagMapper.updateTagUseCount(tagId, 0);
            if (result > 0) {
                userActivityService.recordActivity(operatorId, "TAG_USE_COUNT_RESET", "重置标签使用次数",
                    tagId, "tag", "SUCCESS", 
                    Map.of("tagName", tag.getName(), 
                           "oldUseCount", oldUseCount));
                
                log.info("标签使用次数重置成功: tagId={}, operatorId={}", tagId, operatorId);
                return true;
            }
            
            return false;
        } catch (Exception e) {
            log.error("标签使用次数重置失败", e);
            throw new RuntimeException("标签使用次数重置失败: " + e.getMessage());
        }
    }

    @Override
    public List<ArticleTag> getEnabledTags() {
        return tagMapper.selectEnabledTags();
    }

    @Override
    public List<ArticleTag> getPopularTags(Integer limit) {
        return tagMapper.selectPopularTags(limit);
    }

    @Override
    public List<ArticleTag> getRecentTags(Integer limit) {
        return tagMapper.selectRecentTags(limit);
    }

    @Override
    public boolean existsTagName(String name, Long excludeId) {
        ArticleTag tag = tagMapper.selectTagByName(name, excludeId);
        return tag != null;
    }

    @Override
    public boolean isTagUsedByArticles(Long tagId) {
        return tagMapper.isTagUsedByArticles(tagId);
    }

    @Override
    public Map<String, Object> getTagStatistics() {
        return tagMapper.selectTagStatistics();
    }

    @Override
    public List<Map<String, Object>> getTagStatusDistribution() {
        return tagMapper.selectTagStatusDistribution();
    }

    @Override
    public List<Map<String, Object>> getTagUsageDistribution() {
        return tagMapper.selectTagUsageDistribution();
    }

    @Override
    public List<Map<String, Object>> getTagColorDistribution() {
        return tagMapper.selectTagColorDistribution();
    }

    @Override
    public List<ArticleTag> searchTags(String keyword, Integer limit) {
        return tagMapper.searchTags(keyword, limit);
    }

    @Override
    public List<ArticleTag> getSimilarTags(String tagName, Integer limit) {
        return tagMapper.selectSimilarTags(tagName, limit);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean mergeTags(List<Long> sourceTagIds, Long targetTagId, Long operatorId) {
        try {
            if (sourceTagIds == null || sourceTagIds.isEmpty()) {
                throw new RuntimeException("源标签列表不能为空");
            }

            if (targetTagId == null) {
                throw new RuntimeException("目标标签不能为空");
            }

            if (sourceTagIds.contains(targetTagId)) {
                throw new RuntimeException("源标签列表不能包含目标标签");
            }

            // 检查所有标签是否存在
            // 批量查询标签信息（优化：避免N+1查询）
            List<Long> allTagIds = new ArrayList<>(sourceTagIds);
            allTagIds.add(targetTagId);
            List<ArticleTag> allTags = articleTagMapper.selectTagsByIds(allTagIds);

            // 验证目标标签存在
            ArticleTag targetTag = allTags.stream()
                    .filter(tag -> tag.getId().equals(targetTagId))
                    .findFirst()
                    .orElseThrow(() -> new RuntimeException("目标标签不存在"));

            // 验证所有源标签存在
            for (Long sourceTagId : sourceTagIds) {
                boolean exists = allTags.stream()
                        .anyMatch(tag -> tag.getId().equals(sourceTagId));
                if (!exists) {
                    throw new RuntimeException("源标签不存在: " + sourceTagId);
                }
            }

            // 执行合并
            int result = tagMapper.mergeTags(sourceTagIds, targetTagId);
            if (result > 0) {
                // 删除源标签
                tagMapper.batchDeleteTags(sourceTagIds);

                // 记录合并活动
                userActivityService.recordActivity(operatorId, "TAG_MERGED", "合并标签",
                    targetTagId, "tag", "SUCCESS", 
                    Map.of("targetTagName", targetTag.getName(),
                           "sourceTagIds", sourceTagIds));

                log.info("标签合并成功: targetTagId={}, sourceTagIds={}, operatorId={}", 
                    targetTagId, sourceTagIds, operatorId);
                return true;
            }

            return false;
        } catch (Exception e) {
            log.error("标签合并失败", e);
            throw new RuntimeException("标签合并失败: " + e.getMessage());
        }
    }

    @Override
    public List<ArticleTag> getUnusedTags() {
        return tagMapper.selectUnusedTags();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int cleanupUnusedTags(Integer daysBefore, Long operatorId) {
        try {
            if (daysBefore == null || daysBefore <= 0) {
                daysBefore = 30; // 默认清理30天前的未使用标签
            }

            int cleanupCount = tagMapper.cleanupUnusedTags(daysBefore);

            if (cleanupCount > 0) {
                // 记录清理活动
                userActivityService.recordActivity(operatorId, "TAG_CLEANUP", "清理未使用标签",
                    null, "tag", "SUCCESS", 
                    Map.of("daysBefore", daysBefore,
                           "cleanupCount", cleanupCount));

                log.info("未使用标签清理成功: cleanupCount={}, daysBefore={}, operatorId={}", 
                    cleanupCount, daysBefore, operatorId);
            }

            return cleanupCount;
        } catch (Exception e) {
            log.error("未使用标签清理失败", e);
            throw new RuntimeException("未使用标签清理失败: " + e.getMessage());
        }
    }

    @Override
    public List<Map<String, Object>> getTagTrendStatistics(Integer months) {
        if (months == null || months <= 0) {
            months = 12; // 默认统计12个月
        }
        return tagMapper.selectTagTrendStatistics(months);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean incrementTagUseCount(Long tagId) {
        try {
            int result = tagMapper.incrementTagUseCount(tagId);
            return result > 0;
        } catch (Exception e) {
            log.error("增加标签使用次数失败: tagId={}", tagId, e);
            return false;
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean decrementTagUseCount(Long tagId) {
        try {
            int result = tagMapper.decrementTagUseCount(tagId);
            return result > 0;
        } catch (Exception e) {
            log.error("减少标签使用次数失败: tagId={}", tagId, e);
            return false;
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> syncTagUseCounts(Long operatorId) {
        Map<String, Object> result = new HashMap<>();
        
        try {
            // TODO: 实现标签使用次数同步逻辑
            // 这里需要遍历所有标签，重新计算每个标签在文章中的使用次数
            
            result.put("success", true);
            result.put("message", "标签使用次数同步功能待实现");
            
            return result;
        } catch (Exception e) {
            log.error("同步标签使用次数失败", e);
            result.put("success", false);
            result.put("error", e.getMessage());
            return result;
        }
    }

    @Override
    public Long getTagArticleCount(Long tagId) {
        return tagMapper.selectArticleCountByTagId(tagId);
    }

    @Override
    public Long getTagPublishedArticleCount(Long tagId) {
        return tagMapper.selectPublishedArticleCountByTagId(tagId);
    }

    // ==================== 新增方法实现 ====================

    @Override
    public IPage<ArticleTagResponse> getTagPage(ArticleTagQueryRequest queryRequest) {
        Page<ArticleTagResponse> page = new Page<>(queryRequest.getSafeCurrent(), queryRequest.getSafeSize());
        return articleTagMapper.selectTagPage(page, queryRequest);
    }

    @Override
    public ArticleTagResponse getTagDetailNew(Long tagId) {
        if (tagId == null) {
            return null;
        }
        
        ArticleTag tag = articleTagMapper.selectById(tagId);
        if (tag == null) {
            return null;
        }
        
        ArticleTagResponse response = new ArticleTagResponse();
        BeanUtils.copyProperties(tag, response);
        
        // 获取关联的文章数量
        int articleCount = articleTagRelationService.countArticlesByTagId(tagId);
        response.setArticleCount(articleCount);
        
        return response;
    }

    @Override
    public boolean createTag(ArticleTagCreateRequest createRequest) {
        try {
            // 检查名称是否重复
            if (isTagNameExists(createRequest.getName(), null)) {
                throw new RuntimeException("标签名称已存在");
            }
            
            ArticleTag tag = new ArticleTag();
            BeanUtils.copyProperties(createRequest, tag);
            tag.setUseCount(0);
            tag.setCreateBy("admin"); // 可以从当前用户获取
            tag.setCreateTime(LocalDateTime.now());
            
            return articleTagMapper.insert(tag) > 0;
        } catch (Exception e) {
            log.error("创建标签失败", e);
            throw new RuntimeException("创建标签失败: " + e.getMessage());
        }
    }

    @Override
    public boolean updateTag(ArticleTagUpdateRequest updateRequest) {
        try {
            // 检查名称是否重复
            if (isTagNameExists(updateRequest.getName(), updateRequest.getId())) {
                throw new RuntimeException("标签名称已存在");
            }
            
            ArticleTag tag = new ArticleTag();
            BeanUtils.copyProperties(updateRequest, tag);
            tag.setUpdateBy("admin"); // 可以从当前用户获取
            tag.setUpdateTime(LocalDateTime.now());
            
            return articleTagMapper.updateById(tag) > 0;
        } catch (Exception e) {
            log.error("更新标签失败", e);
            throw new RuntimeException("更新标签失败: " + e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteTag(Long tagId) {
        try {
            // 检查是否有文章使用该标签
            int articleCount = articleTagRelationService.countArticlesByTagId(tagId);
            if (articleCount > 0) {
                throw new RuntimeException("该标签正在被 " + articleCount + " 篇文章使用，无法删除");
            }
            
            // 删除标签
            return articleTagMapper.deleteById(tagId) > 0;
        } catch (Exception e) {
            log.error("删除标签失败", e);
            throw new RuntimeException("删除标签失败: " + e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String batchOperation(TagBatchOperationRequest batchRequest) {
        try {
            String operation = batchRequest.getOperation();
            List<Long> tagIds = batchRequest.getTagIds();
            int count = 0;
            
            switch (operation) {
                case "enable":
                    count = articleTagMapper.batchUpdateTagStatus(tagIds, 1);
                    return "成功启用 " + count + " 个标签";
                    
                case "disable":
                    count = articleTagMapper.batchUpdateTagStatus(tagIds, 0);
                    return "成功禁用 " + count + " 个标签";
                    
                case "delete":
                    // 批量检查是否有标签正在使用（优化：避免N+1查询）
                    List<ArticleTag> tagsToCheck = articleTagMapper.selectTagsByIds(tagIds);
                    for (ArticleTag tag : tagsToCheck) {
                        if (tag.getUseCount() != null && tag.getUseCount() > 0) {
                            throw new RuntimeException("标签 \"" + tag.getName() + "\" 正在被使用，无法删除");
                        }
                    }
                    // 批量删除（使用MyBatis-Plus的批量删除）
                    count = articleTagMapper.deleteBatchIds(tagIds);
                    return "成功删除 " + count + " 个标签";

                case "resetUseCount":
                    // 批量重置使用次数（优化：避免N+1查询）
                    for (Long tagId : tagIds) {
                        articleTagMapper.updateTagUseCount(tagId, 0);
                        count++;
                    }
                    return "成功重置 " + count + " 个标签的使用次数";
                    
                default:
                    throw new RuntimeException("不支持的操作类型: " + operation);
            }
        } catch (Exception e) {
            log.error("批量操作标签失败", e);
            throw new RuntimeException("批量操作失败: " + e.getMessage());
        }
    }

    @Override
    public boolean isTagNameExists(String name, Long excludeId) {
        return articleTagMapper.existsTagByName(name, excludeId);
    }

    @Override
    public List<ArticleTag> getAllTags() {
        log.info("获取所有标签列表");
        try {
            List<ArticleTag> allTags = articleTagMapper.selectAllTags();
            log.info("成功获取所有标签列表，共{}个标签", allTags.size());
            return allTags;
        } catch (Exception e) {
            log.error("获取所有标签列表失败", e);
            throw new RuntimeException("获取所有标签列表失败", e);
        }
    }
}
